﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;

namespace ZX.WebApp.EHR
{
    public partial class hrUserPwd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            string userId = this.User.UserID.ToString();
            string pwd = EncryptData.EncryptSalary.GetUserPwd(userId);
            bool flag = false;
            if (this.tPassword.Value.Trim() == string.Empty) //输入密码为空时
            {
                if (pwd == null) //为第一次配置密码
                {
                    flag = true;
                }
            }
            else
            {
                if (pwd == this.tPassword.Value.Trim()) //旧密码输入正确
                {
                    flag = true;
                }
            }
            if (flag)
            {
                string pwd1 = this.Password1.Value.Trim();
                string pwd2 = this.Password2.Value.Trim();
                if (pwd1 == string.Empty)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script type='text/javascript'>window.alert('密码不能为空！');</script>");
                    return;
                }
                if (pwd1 != pwd2)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script type='text/javascript'>window.alert('两次输入密码不一致！');</script>");
                    return;
                }
                bool b = EncryptData.EncryptSalary.SaveUserPwd(userId, pwd1);
                if (b)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script type='text/javascript'>window.alert('数据保存成功！');</script>");
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script type='text/javascript'>window.alert('数据保存失败！');</script>");
                }
            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script type='text/javascript'>window.alert('旧密码输入不正确！');</script>");
            }
        }
    }
}